package cn.oracle.eshop.commondity.dao.impl;

import cn.oracle.eshop.commondity.dao.PropertyDAO;
import cn.oracle.eshop.commondity.domain.PropertyDO;
import cn.oracle.eshop.commondity.domain.PropertyQuery;
import cn.oracle.eshop.commondity.mapper.PropertyMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**商品属性管理模块的DAO组件
 * @author wyh
 * @ClassName PropertyDAOImpl
 * @date 2022/2/10 /22:02
 */
@Repository
@Slf4j
public class PropertyDAOImpl implements PropertyDAO {
    /**商品属性管理模块的mapper组件*/
    @Autowired
    private PropertyMapper propertyMapper;
    /***
     * 分页查询商品属性
     * @author wyh
     * @date 2022/2/10
     * @param propertyQuery  查询条件
     * @return 商品属性
     */
    @Override
    public List<PropertyDO> listPropertiesByPage(PropertyQuery propertyQuery) {
        try {
          return   propertyMapper.listPropertiesByPage(propertyQuery);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error:{}",e.getMessage());
        }
       return null;
    }
    /***
     * 新增商品属性
     * @author wyh
     * @date 2022/2/10
     * @param propertyDO
     * @return void
     */
    @Override
    public Boolean saveProperty(PropertyDO propertyDO) {
        try {
            propertyMapper.saveProperty(propertyDO);
        } catch (Exception e){
            e.printStackTrace();
        log.error("error:{}",e.getMessage());
        return false;
        }
        return true;
    }
    /**根据ID获取属性值*/
    @Override
    public PropertyDO getPropetryById(Long id) {
        try {
            PropertyDO propetryById = propertyMapper.getPropetryById(id);
            return propetryById;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("error:{}",e.getMessage());
        }
        return null;
    }
    /**更新商品属性*/
    @Override
    public Boolean updateProperty(PropertyDO propertyDO) {
        try {
            propertyMapper.updateProperty(propertyDO);

        } catch (Exception e) {
            e.printStackTrace();
            log.error("error:{}",e.getMessage());
            return  false;
        }
        return true;
    }
}
